﻿using Application.Features.Tenants.DTOs;
using AutoMapper;
using Common.Attributes;
using Domain.Repositories;
using MediatR;
using System.ComponentModel;

namespace Application.Features.Tenants.Queries.GetAll;


/// <summary>
/// 查询启用租户
/// </summary>
[Description("查询启用租户")]
[GroupDescription(("租户管理"))]
public class GetAllTenantsQuery : IRequest<IEnumerable<TenantOptionOutput>>
{
}

public class GetAllTenantsQueryHandler :
    IRequestHandler<GetAllTenantsQuery, IEnumerable<TenantOptionOutput>>
{
    private readonly IMapper _mapper;
    private readonly IMultiTenantRepository _multiTenantRepository;

    public GetAllTenantsQueryHandler(
        IMapper mapper
,       IMultiTenantRepository multiTenantRepository)
    {
        _mapper = mapper;
        _multiTenantRepository = multiTenantRepository;
    }

    public async Task<IEnumerable<TenantOptionOutput>> Handle(GetAllTenantsQuery request, CancellationToken cancellationToken)
    {
        var tenants = await _multiTenantRepository.GetAllEnabledAsync();

        return _mapper.Map<IEnumerable<TenantOptionOutput>>(tenants);
    }
}